import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Login from '@/components/Login'


Vue.use(Router)


export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      redirect:'/login'
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path:'/register',
      name:'Register',
      component:()=>import('../components/Register')
    },
    {
      path:'/admin',
      name:'Admin',
      component:()=>import('../components/admin/AdminIndex'),
      meta:{
        requireAuth:true
      },
      children:[
        {
          path:'/admin/welcome',
          name:'Welcome',
          component:()=>import('../components/admin/welcome/welcome'),
          meta:{
            requireAuth:true
          }
        }
      ]
    }
  ]
})


// 用于创建默认路由
export const createRouter = routes => new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      redirect:'/login'
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path:'/register',
      name:'Register',
      component:()=>import('../components/Register')
    },
    {
      path:'/admin',
      name:'Admin',
      component:()=>import('../components/admin/AdminIndex'),
      meta:{
        requireAuth:true
      },
      children:[
        {
          path:'/admin/welcome',
          name:'welcome',
          component:()=>import('../components/admin/welcome/welcome'),
          meta:{
            requireAuth:true
          }
        }
      ]
    }
  ]
})
